﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClipboardViewer;
using Bitly;

namespace ShortUrlEasyClipboardCopy
{
    public partial class Form1 : Form
    {
        private MyClipboardViewer viewer;

        public Form1()
        {
            InitializeComponent();
            viewer = new MyClipboardViewer(this);
            viewer.ClipboardHandler += this.OnClipBoardChanged;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            this.Visible = false;
            this.Hide();  
        }
        // クリップボードにテキストがコピーされると呼び出される
        private void OnClipBoardChanged(object sender, ClipboardEventArgs args)
        {
            if (args.Text.IndexOf("http://") != -1)
            {
                if (args.Text.Length <= 2060)
                {
                    string ShortUrl = API.Bit("moririring", "R_caa2e6271e586a50e71d810fac6fb411", args.Text, "Shorten");
                    notifyIcon1.BalloonTipText = ShortUrl;
                }
                else
                {
                    //バルーンヒントに表示するメッセージ
                    notifyIcon1.BalloonTipText = "2060文字以上だと短縮URLは作れません";
                }
                notifyIcon1.BalloonTipTitle = "URLコピー";
                notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
                notifyIcon1.ShowBalloonTip(10000);
            }
        }
        private void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
        {
            Clipboard.SetText(notifyIcon1.BalloonTipText);
        }

        private void ExitXToolStripMenuItem_Click(object sender, EventArgs e)
        {
            notifyIcon1.Visible = false; // アイコンをトレイから取り除く
            Application.Exit(); // アプリケーションの終了
        }

    }
}
